home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / lzw4c13.zip / MK_ARC.C < prev    next >
Text File  |  1993-08-29  |  2KB  |  93 lines

  1. /*
  2. **   MK_ARC.C       Copyright (C) 1992 by MarshallSoft Computing, Inc.
  3. **
  4. **   This program is used to compress one or more files into a single
  5. **   archive file. For example, to compress all files ending with the
  6. **   extension '.C' into an archive named 'C.ARF', type:
  7. **
  8. **      MK_ARC *.C C.ARF
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <dos.h>
  14. #include <fcntl.h>
  15. #include <sys\types.h>
  16. #include <sys\stat.h>
  17. #include <io.h>
  18.  
  19. #include "LZW4C.H"
  20. #include "RW_IO.H"
  21. #include "DIR_IO.H"
  22.  
  23. void SayError(int);
  24.  
  25. void main(argc,argv)
  26. int argc;
  27. char *argv[];
  28. {int i, k;
  29.  int RetCode;
  30.  float Ratio;
  31.  long TotalCount = 0;
  32.  char Filename[15];
  33.  int Files = 0;
  34.  char *Ptr;
  35.  /* begin */
  36.  if(argc!=3)
  37.    {printf("Usage: MK_ARC <filespec> <archive_file_name>\n");
  38.     exit(1);
  39.    }
  40.  RetCode = InitLZW(malloc,14);
  41.  if(RetCode<0)
  42.    {SayError(RetCode);
  43.     exit(2);
  44.    }
  45.  /* flush the keyboard */
  46.  puts("\nMK_ARC 1.0: Type any key to abort...");
  47.  /* open output file for compression */
  48.  Ptr = argv[2];
  49.  for(i=0;i<strlen(Ptr);i++) Ptr[i] = toupper(Ptr[i]);
  50.  if(!WriterOpen(Ptr)) exit(4);
  51.  for(i=0;;i++)
  52.    {if(kbhit())
  53.       {puts("\n...Aborted by user !");
  54.        break;
  55.       }
  56.     if(i==0) RetCode = FindFirst(argv[1],Filename);
  57.     else RetCode = FindNext(Filename);
  58.     if(!RetCode) break;
  59.     /* make filename upper case */
  60.     for(k=0;k<strlen(Filename);k++) Filename[i] = toupper(Filename[i]);
  61.     /* open input file for compression */
  62.     if(strcmp(Filename,Ptr)==0)
  63.       {printf("WARNING: Compress file same as archive file = %s (skipping)\n",
  64.          Filename);
  65.        continue;
  66.       }
  67.     if(!ReaderOpen(Filename)) exit(3);
  68.     /* write filename to output file */
  69.     Writer('\0');
  70.     for(k=0;k<strlen(Filename);k++) Writer(Filename[k]);
  71.     Writer('\0');
  72.     /* do the compression */
  73.     Files++;
  74.     printf("Compressing %12s ",Filename);
  75.     if((RetCode=Compress(Reader,Writer))<0)
  76.       {SayError(RetCode);
  77.        exit(5);
  78.       }
  79.     /* report compression ratio */
  80.     if(ReaderCount() > 0)
  81.        {Ratio = (float)(WriterCount()-TotalCount)/(float)ReaderCount();
  82.         printf(" OK (%0.2f)\n",Ratio);
  83.         TotalCount = WriterCount();
  84.        }
  85.     else puts("???");
  86.     /* close file */
  87.     ReaderClose();
  88.    }
  89.  WriterClose();
  90.  TermLZW(free);
  91.  printf("\n%d files compressed\n",Files);
  92.  exit(0);
  93. }